package com.jfinal.bloglist.config;

import com.jfinal.bloglist.controller.BlogController;
import com.jfinal.bloglist.model.Blog;
import com.jfinal.bloglist.model.BlogType;
import com.jfinal.config.*;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.druid.DruidPlugin;
import com.jfinal.render.ViewType;

/**
 * Title:
 * Description:
 *
 * @version 2.0
 * @author: Yung Fu(FUYUNGCN AT GMAIL DOT com)
 * @since: 14-10-11 下午10:38
 */
public class BlogConfig extends JFinalConfig {

    @Override
    public void configConstant(Constants me) {
        me.setViewType(ViewType.FREE_MARKER);
        me.setDevMode(true);
    }

    @Override
    public void configRoute(Routes me) {
        me.add("/blog", BlogController.class);
    }

    @Override
    public void configPlugin(Plugins me) {
        loadPropertyFile("blog_config.txt");
//        C3p0Plugin plugin = new C3p0Plugin(getProperty("jdbcUrl"), getProperty("userName"), getProperty("password"));

        DruidPlugin plugin = new DruidPlugin(getProperty("jdbcUrl"), getProperty("userName"), getProperty("password"));
        me.add(plugin);// 添加Druid连接池


        ActiveRecordPlugin activeRecordPlugin = new ActiveRecordPlugin(plugin);
        activeRecordPlugin.addMapping("blog", Blog.class);
        activeRecordPlugin.addMapping("blog_type", BlogType.class);

        me.add(activeRecordPlugin);// 添加ActiveRecord插件
    }

    @Override
    public void configInterceptor(Interceptors me) {

    }

    @Override
    public void configHandler(Handlers me) {

    }
}
